package org.dk.service.Impl;

import org.dk.mapper.TbAddressMapper;
import org.dk.pojo.TbAddress;
import org.dk.pojo.TbAddressExample;
import org.dk.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class AddressServiceImpl implements AddressService {

    @Autowired
    private TbAddressMapper addressMapper;

    @Override
    public List<TbAddress> selectAddress(String username) {
        TbAddressExample example = new TbAddressExample();
        TbAddressExample.Criteria criteria = example.createCriteria();
        criteria.andUserIdEqualTo(username);
        List<TbAddress> addresses = addressMapper.selectByExample(example);
        return addresses;
    }

    @Override
    public void addAddress(TbAddress address) {
        addressMapper.insertSelective(address);
    }

    @Override
    public void deleteAddress(Long id) {
        addressMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void updateAddress(Long id, String username) {
        addressMapper.updateAddress(username);
        addressMapper.updateByID(id);
    }

    @Override
    public TbAddress selectAddress(Long id) {
        return addressMapper.selectByPrimaryKey(id);
    }
}
